Strict

Import agfx

Global myTmpScreen:TTmpScreen

Class TAgfx_test_app Extends TFramework

	Method OnCreate:Int()
		
		Super.OnCreate()
				
		DISPLAY.SetVirtualSize(480,320)
		Self.fps_On =True
		myTmpScreen = New TTmpScreen		
		myTmpScreen.Prepare()
		
		
		
		Return 0
	End
	

	
End


Class TTmpScreen Extends TScreen

	Field cube2:TBox2DBody
	Field ball1:TBox2DBody
	Field i:Int
	' START when app is created
	Method Start:Void()
		
		IMAGES.Load("box.png","BOX")
		IMAGES.Load("ball_pink.png","BALL")
		
		' create world
		BOX2D.CreateWorld(New b2Vec2(0,10),True,100,True)
		
		' create ground
		Local ground_left:TBox2DBody = BOX2D.CreateStaticBox("GROUND_LEFT",DISPLAY.VSCREEN_HALF_WIDTH,DISPLAY.VSCREEN_HEIGHT-20,DISPLAY.VSCREEN_WIDTH,10)
		ground_left.body.SetAngle(DEG2RAD*-45.0)
		
		Local ground_right:TBox2DBody = BOX2D.CreateStaticBox("GROUND_RIGHT",DISPLAY.VSCREEN_HALF_WIDTH,DISPLAY.VSCREEN_HEIGHT-20,DISPLAY.VSCREEN_WIDTH,10)
		ground_right.body.SetAngle(DEG2RAD*45.0)
		
		
		Local ground_oval:TBox2DBody = BOX2D.CreateStaticCircle("GROUND_OVAL",DISPLAY.VSCREEN_HALF_WIDTH,DISPLAY.SCREEN_HEIGHT-250,32)
		
		' create dynamic box
		
		Local fixt:b2FixtureDef = New b2FixtureDef()
		fixt.density = 1.0
		fixt.friction = 0.3
		
		Local cube:TBox2DBody = BOX2D.CreateDynamicBox("BOX",320-32,10,32,64,fixt)
		cube.body.SetAngularVelocity(5)
		
		
		' create dynamic circle
		
		Local fixt_ball:b2FixtureDef = New b2FixtureDef()
		fixt_ball.density = 2.0
		fixt_ball.restitution = 0.2
		fixt_ball.friction = 0.5
		
		Local ball:TBox2DBody = BOX2D.CreateDynamicCircle("CIRCLE",320+32,10,16,fixt)
		
		' create dynamic cube from Sprite
		Local spr:TSprite = New TSprite("spr_box",IMAGES.Find("BOX"),320+64,10)
		Self.cube2 = BOX2D.CreateDynamicBox("IMG_BOX",spr,fixt)
		
		'create dynamic circle from sprite
		Local spr_ball:TSprite = New TSprite("spr_ball",IMAGES.Find("BALL"),320-64,10)
		Self.ball1 = BOX2D.CreateDynamicCircle("PHX_BALL",spr_ball,fixt_ball)
		
		' create polygon shape
		
		Local vertices:FlashArray<b2Vec2> = New FlashArray<b2Vec2>()
		vertices = CreateFlashArrayFromFile("triangle_bl.txt")
		Local poly:TBox2DBody = BOX2D.CreateDynamicPolygon("POLY",130,30,32,32,vertices,fixt_ball)
	End
	
	' main app logic loop update
	Method Update:Void()
		
		if MOUSE.Hit() And KeyDown(KEY_SHIFT) Then			
			Local fixt_b:b2FixtureDef = New b2FixtureDef()
			fixt_b.density = 2.0
			fixt_b.restitution = 0.2
			fixt_b.friction = 0.5
			BOX2D.CreateDynamicCircle("CIRCLE",MOUSE.x,MOUSE.y,16,fixt_b)
		EndIf
		
		BOX2D.Update()
	End
	
	' main app render loop
	Method Render:Void()
		Cls
		BOX2D.Render()
		Self.cube2.Render()
		Self.ball1.Render()
	End
End
